<h2><span ng-bind='action'></span> Challenge</h2>
<form ng-submit='saveChallenge()' name='challengeForm'>
  <div class='well'>
    <div class='row'>
        <div class='col-md-8'>
          <div class='form-group'>
              <label for='name'>Name</label>
              <input id='name' name='name' placeholder='Name'
                ng-model='challenge.name' class='form-control'
                required>
          </div>
        </div>
        <div class='col-md-4'>
          <div class='form-group'>
              <label for='points'>Points</label>
              <input id='points' name='points' class='form-control'
                type='number' ng-model='challenge.points' placeholder='0'
                required>
          </div>
        </div>
    </div>
    <div class='form-group'>
        <label for='description'>Description</label>
        <textarea id='description' name='description' class='form-control'
          ng-model='challenge.description' required
          placeholder='Description'></textarea>
    </div>
    <div class='row'>
      <div class='col-md-6'>
        <div class='form-group'>
            <label for='validator'>Validator</label>
            <select id='validator' name='validator' class='form-control'
              ng-options='key as value.name for (key, value) in config.validators'
              ng-model='challenge.validator' required>
            </select>
        </div>
      </div>
      <div class='col-md-6'>
        <div class='form-group'>
            <label for='answer'>Answer</label>
            <input id='answer' name='answer' class='form-control'
              placeholder='{{answerPlaceholder}}' ng-model='challenge.answer'
              ng-required='!editing'>
        </div>
      </div>
    </div>
    <div class='form-group'>
        <label for='unlocked'>Unlocked</label>
        <input id='unlocked' name='unlocked' value='1' type='checkbox'
          ng-model='challenge.unlocked'>
    </div>
  </div>
  <div class='well'>
    <h4>Tags</h4>
    <table class='table text-light' id='tag-table'>
      <thead>
        <tr><th class='col-md-2'>Tag Name</th>
            <th class='col-md-6'>Tag Description</th>
            <th class='col-md-1'></th></tr>
      </thead>
      <tbody>
        <tr ng-repeat='tag in tags | orderBy:"name"'>
          <td>{{tag.name}}</td><td>{{tag.description}}</td>
          <td><a
               class='btn btn-sm {{hasTag(tag.tagslug) ? "btn-success" : "btn-info"}}'
               ng-click='toggleTag(tag.tagslug)'>
                <span ng-if= 'hasTag(tag.tagslug)'>&#x2713;</span>
              </a>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class='well'>
    <h4>Attachments</h4>
    <table class='table text-light' id='attachment-table'>
        <thead>
            <tr><th class='col-md-4'>File</th><th
                    class='col-md-4'>Filehash</th><th class='col-md-1'></th></tr>
        </thead>
        <tbody>
        <tr ng-repeat='attachment in challenge.attachments'>
            <td>{{attachment.filename}}</td>
            <td>{{attachment.aid}}</td>
            <td><a class='btn btn-sm btn-warning'
              ng-click='deleteAttachment(attachment)'>&#x2715;</a></td>
        </tr>
        <tr>
          <td colspan='2' class='col-md-8'>
            <label class='label-sized' for='choose-attachment'>Add Attachment</label>
            <select id='choose-attachment' ng-model='attachmentType' class='form-control'>
              <option value='new'>New</option>
              <option ng-repeat='a in attachments' value='{{a.aid}}'>{{a.filename}}</option>
            </select>
          </td><td class='button-top col-md-1'>
            <a class='btn btn-sm btn-info' ng-click='addAttachment()'>&#x271b;</a>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class='well'>
    <h4>Prerequisite</h4>
    <div class='form-group'>
      <label for='prereq_type'>Type</label>
      <select id='prereq_type' ng-model='challenge.prerequisite.type'
        ng-change='updatePrerequisite()' class='form-control'>
        <option value='None'>None</option>
        <option value='solved'>Solved Another</option>
      </select>
    </div>
    <div class='form-group'
      ng-show='challenge.prerequisite.type=="solved"'>
      <label for='prereq_challenge'>Required Challenge</label>
      <select id='prereq_challenge'
        ng-model='challenge.prerequisite.challenge'
        class='form-control'>
        <option ng-repeat='ch in challengeList' value='{{ch.cid}}'
          ng-bind='ch.name'></option>
      </select>
    </div>
  </div>
  <input type='submit' class='btn btn-primary' value='Save'i
    ng-disabled='challengeForm.$invalid'>
</form>

<!-- TODO: Display solves -->
